package com.zc.backend.service.impl;

import com.zc.backend.entity.Page;
import com.zc.backend.entity.Student;
import com.zc.backend.mapper.StudentMapper;
import com.zc.backend.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public List<Student> queryAll(Page page) {
        return studentMapper.queryAll(page.getPager()*page.getPageSize(),page.getPageSize());
    }

    @Override
    public void add(Student student) {
        studentMapper.add(student);
    }

    @Override
    public void delete(Integer id) {
        studentMapper.delete(id);
    }

    @Override
    public Student queryById(Integer id) {
        return studentMapper.queryById(id);
    }

    @Override
    public void update(Student student) {
        studentMapper.update(student);
    }

    @Override
    public Integer count() {
        return studentMapper.count();
    }

    @Override
    public List<Student> queryByName(String name,Page page) {
        System.out.println("start"+(page.getPager()-1) * page.getPageSize()+"end"+page.getPageSize());
        System.out.println("name="+name);
        List<Student> students = studentMapper.queryByName(name, (page.getPager()-1) * page.getPageSize(), page.getPageSize());
        System.out.println("查到的数据"+students);
        return students;
    }

    @Override
    public Integer countByName(String name) {
        return studentMapper.countByName(name);
    }

}
